package com.apexedu.sync.exception;

import java.util.HashMap;
import java.util.Map;

/**
 * 同步异常类
 * Created by ly on 2015/1/12.
 */
public class AuCSyncException extends Exception {

    /**
     * 未知错误
     */
    public static final int UNKNOWN_SERVICE_ERROR = -1;
    public static final int ENCRYPT_NO_MATCH = 1; //校验码未通过
    public static final int TABLE_VIEW_COLUMN_NO_FOUND = 11; //表/视图缺少字段
    public static final int MENU_DUPLICATE = 21; //菜单重复

    /**
     * 默认错误信息集合
     */
    private static Map<Integer, String> defaultMessages = new HashMap<Integer, String>();

    static {
        defaultMessages.put(UNKNOWN_SERVICE_ERROR, "未知错误");
        defaultMessages.put(ENCRYPT_NO_MATCH, "校验码未通过");
        defaultMessages.put(TABLE_VIEW_COLUMN_NO_FOUND, "表/视图缺少字段");
        defaultMessages.put(MENU_DUPLICATE, "菜单重复");
    }

    public static String getDefaultMessage(int code) {
        return defaultMessages.get(code);
    }

    private int errorcode = UNKNOWN_SERVICE_ERROR;

    public AuCSyncException(int code, String message) {
        super(message == null ? getDefaultMessage(code) : message);
        this.errorcode = code;
    }

    public int getErrorcode() {
        return errorcode;
    }
}
